package com.hmkj.admin.controller.invest;

import com.hmkj.admin.controller.BaseController;
import com.hmkj.admin.controller.GenericController;
import com.hmkj.common.entity.ResultEntity;
import com.hmkj.common.entity.dtgrid.DtGrid;
import com.hmkj.common.utils.StringUtils;
import com.hmkj.common.utils.ValidateUtils;
import com.hmkj.core.exception.BussinessException;
import com.hmkj.core.model.invest.InvestModel;
import com.hmkj.core.po.invest.Invest;
import com.hmkj.core.service.invest.InvestService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(BaseController.BASE_URI)
public class InvestJsonController extends GenericController<Integer, Invest> {

    @Autowired
    private InvestService investService;

    /**
     * 投资人列表json数据
     *
     * @param dtGridPager
     * @return
     */
    @ResponseBody
    @RequestMapping("/invest/list.json")
    @RequiresPermissions("sys:invest:list")
    public DtGrid listJson(String dtGridPager) throws Exception{
        dtGridPager = dataAuthority(dtGridPager);
        return investService.getDtGridList(dtGridPager, InvestModel.class);
    }

    /**
     * 编辑账户资金
     *
     * @param invest
     * @return
     */
    @ResponseBody
    @RequestMapping("/invest/edit.json")
    @RequiresPermissions("sys:invest:edit")
    public ResultEntity editJson(Invest invest,Integer type) throws Exception {
        if(StringUtils.isBlank(invest.getInvestAccount())){
            throw new BussinessException("输入金额不能为空");
        }
        if(!ValidateUtils.isPrice(invest.getInvestAccount().toString())){
            throw new BussinessException("输入金额格式不正确");
        }

         investService.editInvestAccount(invest,type);
         return ok();
    }
}
